package com.cus.tom.transfer.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.plata.base.aclr.common.SilentTask;
import com.plata.base.aclr.common.TaskEngine;

public abstract class BaseDao {

    public void doInBackground(Runnable r) {
        SilentTask task = new SilentTask(getClass().getSimpleName()) {
            @Override
            public void runInBackground() {
                r.run();
            }
        };
        TaskEngine.getInstance().submit(task);
    }

    protected synchronized SQLiteDatabase getDataBase() {
        return DatabaseManager.getInstance().openDatabase();
    }

    protected synchronized void closeDataBase() {
        DatabaseManager.getInstance().closeDatabase();
    }

    protected void closeCursor(Cursor c) {
        if (c != null && !c.isClosed()) {
            try {
                c.close();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }

    public abstract void delete(long id);
}
